<!DOCTYPE html>
<html lang="ch" xmlns:th="http://www.thymeleaf.org">
<head>
   <th:block th:include="inc :: header('合同管理')" />
</head>
<body>
    <table id="table" lay-filter="table"></table>
    <script type="text/html" id="activeBar">
        <a class="layui-btn layui-btn-xs" lay-event="check">查看合同</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="failed">合同作废</a>
    </script>
    <script type="text/html" id="toolbar">
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="ipn1" placeholder="请输入合同编号" style="height: 30px">
            </div>
            <a class="layui-btn layui-btn-sm layui-bg-blue" lay-event="search">查询</a>
            <a class="layui-btn layui-btn-sm" lay-event="add">新增合同</a>
    </script>
    <script>
        layui.use('table',function () {
            var tb = layui.table;

            tb.render({
                elem:'#table',
                url:'/agc/find',
                page:true,
                height:'full-0',
                toolbar:'#toolbar',
                cols:[
                    [
                        {field:'agreementId',title:'合同编号',align:'center',width:150},
                        {field:'getUserName',title:'出租方名称',align:'center',width:100,},
                        {field:'getUserIdcard',title:'出租方身份证号',align:'center',width:180},
                        {field:'setUserName',title:'承租方名称',align:'center',width:100},
                        {field:'setUserIdcard',title:'承租方身份证号码',align:'center',width:180},
                        {field:'homes',title:'出租地址',align:'center',width:250},
                        {field:'getMoney',title:'租金',align:'center',width:150,
                            templet:function (res) {
                                return res.getMoney+"/"+res.getDw;
                            }
                        },
                        {field:'zfb',title:'月涨幅比',align:'center',width:150},
                        {field:'startEndDate',title:'合同签订时间',align:'center',width:250,
                            templet:function (res) {
                                return res.createDate+"&nbsp;至&nbsp;"+res.enDate;
                            }
                        },
                        {field:'status',title:'合同状态',align:'center',width:150},
                        {field:'remark',title:'备注',align:'center',width:250},
                        {fixed:'right',title:'操作',align:'center',width:200,toolbar:'#activeBar'}
                    ]
                ]
            });
            tb.on('toolbar(table)',function (obj) {
                switch (obj.event) {
                    case 'add':
                        layer.open({
                            type:2,
                            title:'合同新增',
                            content:'/agc/addEdit',
                            area:['60%','90%'],
                            maxmin:true,
                            anim:1,
                            btn:['确定保存','取消关闭'],
                            yes:function(index,layero){
                                //获取表单
                                var f = layer.getChildFrame('form',index);
                                var data = f.serialize();
                                $.ajax({
                                    type:'post',
                                    url:'/agc/add',
                                    data:data,
                                    dataType:'json',
                                    success:function(result){
                                        layer.alert(result.msg);
                                        if(result.is){
                                            layer.close(index);
                                            layui.table.reload('table');
                                        }
                                    }
                                })
                            },
                            btn2:function (index,layero) {
                                //TODO 删除上传的文件及信息
                                var agreementId = layer.getChildFrame("form",index).find('#agreementId').val();
                                var tabName = "t_agreement";
                                alert(agreementId);
                                layer.close(index);
                            }
                        })
                        break;
                }
            });
            //行工具条的点击
            tb.on('tool(table)',function (obj) {
                var data = obj.data;
                console.log(data.id);
                switch (obj.event) {
                    case 'check':
                        layer.open({
                            type:2,
                            content: '/agc/addEdit?id='+data.id,
                            area:['100%','100%'],
                            maxmin:true,
                            anim: 4
                        });
                        break;
                }
            });
        })
    </script>
</body>
</html>